<!DOCTYPE html>
<html lang="en" style="background:#fff;">
<head>
    <base href="${basePath}">
    <#include "common/top.html"/>
</head>
<body style="background:#fff;">
<form class="layui-form layui-form-pamel" name="form1" id="form1" method="post">
    <div class="searchbox demoTable" id="searchbox">

        <div class="layui-form-item">
            <a onclick="importTable()" class="layui-btn-tan">
                <i class="layui-icon">&#xe608;</i> 导入
            </a>

            <div class="layui-inline">
                <label class="layui-form-label">项目：</label>
                <div class="layui-input-inline">
                    <input class="layui-input" type="text" maxlength="50" name="projectName" id="projectName" placeholder="请输入项目"/>
                </div>
            </div>
            <input type="button" value="查询" onclick="searchs();" class="layui-btn layui-btn-red mr10"/>
        </div>
    </div>
</form>

<div style="overflow:auto;width: 100%;padding-bottom: 20px;">
    <table id="simple-table" class="layui-table" lay-filter="simple-table">
    </table>
    <script type="text/html" id="barTable">
        <a class="layui-icon colored7764" lay-event="previewFlag" title="预览">预览</a>
        <a class="layui-icon colored7764" lay-event="editFlag" title="编辑">编辑</a>
        <a class="layui-icon colored7764" lay-event="delFlag" title="删除">删除</a>
        <a class="layui-icon colored7764" lay-event="codeFlag" title="生成代码">生成代码</a>
    </script>
</div>

</body>
</html>
<script type="text/html" id="delStatus">
    {{# if(d.delStatus == 'Y'){ }}
    <span style="color: #ff0e15">销户</span>
    {{# }else{ }}
    <span style="color: #2daa18">正常</span>
    {{#}}}
</script>


<script type="text/javascript">
    var formTable;
    var table;
    var form;

    layui.use(['form','table','laydate'], function(){
        form = layui.form;
        table = layui.table;
        form.render();
        formTable = table.render({
            elem: '#simple-table',
            url:'${basePath}tool/getTablelist',
            method: 'POST',
            where:{ti:new Date().getTime()},
            request: {
                pageName: 'currentPage' //页码的参数名称，默认：page
                ,limitName: 'showCount' //每页数据量的参数名，默认：limit
            },
            response: {
                statusName: 'status' //数据状态的字段名称，默认：code
                ,statusCode: true //成功的状态码，默认：0
                ,msgName: 'msg' //状态信息的字段名称，默认：msg
                ,countName: 'totalResult' //数据总数的字段名称，默认：count
                ,dataName: 't' //数据列表的字段名称，默认：data
            },
            cols: [[
                {field:'tableId', title: '编号'}
                ,{field:'tableName', title: '表名称'}
                ,{field:'tableComment', title: '表描述'}
                ,{field:'className', title: '实体类名称'}
                ,{field:'createTime', title: '创建时间'}
                ,{field:'updateTime', title: '更新时间'}
                ,{title: '操作' ,width:178, align:'center', toolbar: '#barTable'}
            ]],
            page: true
        });

        table.on('tool(simple-table)', function(obj){
            var data = obj.data;
            if(obj.event === 'delFlag'){
                layer.confirm('真的删除<span style="color: #9f191f">'+data.tableName+'</span>吗?', function(index){
                    $.ajax({
                        url : '${basePath}tool/deleteTable',
                        data : {
                            tableIds : data.tableId
                        },
                        type : "POST",
                        success : function(data) {
                            if (data.status == true) {
                                obj.del(); //删除表格里的行
                                layer.close(index);
                                searchs();
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    });
                });
            }else if(obj.event === 'editFlag'){

                window.location.href="${basePath}tool/editTable?tableId=" + data.tableId;

            }else if(obj.event === 'codeFlag'){
                layer.confirm('真的生成<span style="color: #9f191f">'+data.tableName+'</span>表代码吗?', function(index){
                    window.location.href="${basePath}tool/createCode?tableName=" + data.tableName;
                });
            }else if(obj.event === 'accountJournal'){
                window.location.href="${basePath}account/accountJournal?accountCode=" + data.accountCode;
            }


        });
    });

    //检 索
    function searchs() {
        formTable.reload({
            where: {
                accountCode: $("#accountCode").val()
                ,projectName: $("#projectName").val()
                ,business: $("#business").val()
            },page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }




    function importTable(){
        layer.open({
            type: 2,//此处以iframe举例
            title: '导入表',
            area: ['850px', '550px'],
            maxmin: true,
            content: '${basePath}tool/importTable',
            btn: ['保存', '关闭'], //只是为了演示
            yes: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.save();
            },
            no: function (index) {
                layer.close(index);
            },
            end: function () {
                searchs()
            }
        });
    }

</script>
